package net.gq.logistics.service.serviceimpl;

import net.gq.logistics.mapper.OrderDetailMapper;
import net.gq.logistics.mapper.OrderMapper;
import net.gq.logistics.pojo.Order;
import net.gq.logistics.pojo.OrderDetail;
import net.gq.logistics.pojo.OrderDetailExample;
import net.gq.logistics.pojo.OrderExample;
import net.gq.logistics.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ASUS
 * @date 2020/5/27
 */
@Service("orderService")
public class OrderServiceImpl implements OrderService {


    @Resource(name = "orderMapper")
    private OrderMapper mapper;

    @Resource(name = "orderDetailMapper")
    private OrderDetailMapper orderDetailMapper;

    @Override
    public int deleteByPrimaryKey(Long orderId) {
        return mapper.deleteByPrimaryKey(orderId);
    }

    @Override
    public int insert(Order record) {
        return mapper.insert(record);
    }

    @Override
    public int insertSelective(Order record) {
        return mapper.insertSelective(record);
    }

    @Override
    public List<Order> selectByExample(OrderExample example) {
        return mapper.selectByExample(example);
    }

    @Override
    public Order selectByPrimaryKey(Long orderId) {
        return mapper.selectByPrimaryKey(orderId);
    }

    @Override
    public int updateByPrimaryKeySelective(Order record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Order record) {
        return mapper.updateByPrimaryKey(record);
    }

    @Override
    public List<OrderDetail> selectOrderDetailsByOrderId(Long orderId) {

        OrderDetailExample orderDetailExample = new OrderDetailExample();

        OrderDetailExample.Criteria criteria = orderDetailExample.createCriteria();

        criteria.andOrderIdEqualTo(orderId);
        List<OrderDetail> orderDetails = orderDetailMapper.selectByExample(orderDetailExample);


        return orderDetails;
    }
}
